home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / COMMON / TOOLS / VB / CABINETS / MSDAO350.CAB / icontrols / ImageDisplayer.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-01-08  |  2.2 KB  |  67 lines

  1. package icontrols;
  2.  
  3. import com.ms.wd.ui.Graphics;
  4. import com.ms.wd.ui.Image;
  5. import com.ms.wd.ui.Point;
  6. import com.ms.wd.ui.Rectangle;
  7.  
  8. public class ImageDisplayer {
  9.    public static final int ALIGN_LEFT = 1;
  10.    public static final int ALIGN_RIGHT = 2;
  11.    public static final int ALIGN_HCENTER = 4;
  12.    public static final int ALIGN_TOP = 16;
  13.    public static final int ALIGN_BOTTOM = 32;
  14.    public static final int ALIGN_VCENTER = 64;
  15.    public static final int ALIGN_NONE = Integer.MIN_VALUE;
  16.    private int m_nAlign = Integer.MIN_VALUE;
  17.    private boolean m_bStretch = false;
  18.  
  19.    public void paintIn(Graphics g, Rectangle bounds, Rectangle clipRect, Image img) {
  20.       this.paintIn(g, bounds, clipRect, img, (Point)null);
  21.    }
  22.  
  23.    public void paintIn(Graphics g, Rectangle bounds, Rectangle clipRect, Image img, Point imageSize) {
  24.       if (this.m_bStretch) {
  25.          g.drawImage(img, bounds.x, bounds.y, bounds.width, bounds.height, true);
  26.       } else {
  27.          Point pointImageSize = imageSize;
  28.          if (imageSize == null) {
  29.             pointImageSize = img.getSize();
  30.          }
  31.  
  32.          int nXLoc = bounds.x;
  33.          int nYLoc = bounds.y;
  34.          if ((this.m_nAlign & 2) != 0) {
  35.             nXLoc = bounds.x + bounds.width - pointImageSize.x;
  36.          } else if ((this.m_nAlign & 4) != 0) {
  37.             nXLoc = bounds.x + (bounds.width - pointImageSize.x) / 2;
  38.          }
  39.  
  40.          if ((this.m_nAlign & 32) != 0) {
  41.             nYLoc = bounds.y + bounds.height - pointImageSize.y;
  42.          } else if ((this.m_nAlign & 64) != 0) {
  43.             nYLoc = bounds.y + (bounds.height - pointImageSize.y) / 2;
  44.          }
  45.  
  46.          g.drawImage(img, nXLoc, nYLoc);
  47.       }
  48.  
  49.    }
  50.  
  51.    public void setStretch(boolean bStretch) {
  52.       this.m_bStretch = bStretch;
  53.    }
  54.  
  55.    public boolean isStretch() {
  56.       return this.m_bStretch;
  57.    }
  58.  
  59.    public void setAlignment(int nAlign) {
  60.       this.m_nAlign = nAlign;
  61.    }
  62.  
  63.    public int getAlignment() {
  64.       return this.m_nAlign;
  65.    }
  66. }
  67.